'use strict';

module.exports = app => {
  const { INTEGER } = app.Sequelize;
  const CourseStudent = app.model.define(
    'CourseStudent',
    {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      course_start_id: INTEGER(11),
      student_id: INTEGER(11),
        course_id: INTEGER(11),
        category_id: INTEGER(11),
        teacher_id: INTEGER(11),
    },
    {
      tableName: 'course_student',
      timestamps: true, // 启用时间戳(createdAt, updatedAt)
      updatedAt: false, // 不想要 updatedAt
      createdAt: 'created_at', // 想要  createdAt 但是希望名称叫做 created_at
    }
  );
    CourseStudent.associate = () => {
        const { Student, Course, CourseStart, Teacher } = app.model;
        CourseStudent.hasOne(Course, {foreignKey: 'id', sourceKey: 'course_id'})
        CourseStudent.hasOne(Student, {foreignKey: 'id', sourceKey: 'student_id'})
        CourseStudent.hasOne(CourseStart, {foreignKey: 'id', sourceKey: 'course_start_id'})
        CourseStudent.hasOne(Teacher, {foreignKey: 'id', sourceKey: 'teacher_id'})
        CourseStudent.belongsTo(CourseStart, { foreignKey: 'course_start_id', targetKey: 'id'})
    };
  return CourseStudent;
};
